/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hu
 * Date: 2024-04-26
 * Time: 20:35
 */
import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
        //求一个整数，在内存当中存储时，二进制1的个数。
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数字：");
        int a = sc.nextInt();
        int count = 0;
        while(a != 0){
            if(a % 2 == 1){
                count++;
            }
            a = a / 2;
        }
        System.out.println("二进制1的个数:" + count);
    }
    public static void main8(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入被除数");
        int a = sc.nextInt();
        System.out.println("请输入除数");
        int b = sc.nextInt();
        int r = 1;
        while(b != 0){
            r = a % b;
            a = b;
            b = r;
        }
        System.out.println("最小公约数是：");
        System.out.println(a);
    }
    public static void main7(String[] args) {
        double sum=0;
        int i;
        for (i = 1; i <= 100; i++) {
            if (i % 2 == 1) //
            {
                sum += 1.0 / i;
            } else if (i % 2 == 0) {
                sum -= 1.0 / i;
            }
        }
        System.out.println(sum);
    }
    public static void main5(String[] args) {
        double i = 1.0;
        double j = 5;
        System.out.println("i % j ="+ i % j);
    }
    public static void main6(String[] args) {
        double sum = 0;
        for (int i = 1; i <= 100; i++) {
            if(i % 2 == 1){
                sum += 1.0 / i;
            }else if(i % 2 ==0){
                sum -= 1.0 / i;
            }
        }
        System.out.println(sum);
    }
    public static void main3(String[] args) {
        //水仙花数
        for (int i = 100; i < 1000; i++) {
            int a = (i / 10) % 10;
            int b = i / 100;
            int c = i % 10;
            if(i == a*a*a + b*b*b + c*c*c){
                System.out.println(i);
            }
        }
    }
    public static void main2(String[] args) {
        //打印X形
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入图形的大小：");
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            for(int j = 0;j < n;j++){
                if(i == j || i +j == n - 1){
                    System.out.print("*");
                }else{
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
    public static void main1(String[] args) {
        //判断素数
        int j = 0;
        for (int i = 2; i <= 100; i++) {
            for( j = 2;j <= i; j++){
                if(i % j ==0){
                    break;
                }

            }
            if( i == j){
                System.out.println(i);
            }
        }
    }
}
